package com.wll.exportfile.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {

    @RequestMapping("/test/export")
    public void export(HttpServletRequest request, HttpServletResponse response) {
        //导出的数据
        List<Map<String, String>> exportData = new ArrayList<Map<String, String>>();
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            exportData.add(new HashMap<String, String>() {{
                put("requestUri", ("西安" + finalI));
                put("requestMethod", "詹三" + (finalI * 10));
                put("ip", "127.0.0.1");
                put("errorSimpleInfo", "{adasdasd}");
                put("createDate", "2023-01-05");
                put("creatorName", "lili");
            }});
        }
        // 1.导出的header标题设置
        String[] headers = {"请求地址", "请求方式", "IP地址", "简要信息", "异常时间", "创建人"};
        // 2.导出header对应的字段设置
        String[] columns = {"requestUri", "requestMethod", "ip", "errorSimpleInfo", "createDate", "creatorName"};

        try {
//            ExcelStupditUtil.export(exportData, headers, columns, "危险源信息", response);
            System.out.println("导出结束..................");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
